<template>
    <div id="exchange-batch-stock" class="order-content">
        <div class="top" style="width: 100%; overflow: auto">
            <el-row class="row-height top-row" style="border-bottom: 1px solid #c9c9c9">
                <el-col :key="renderUUID" :span="8" class="col-box" style="border-right: 1px solid #c9c9c9">
                    <h3 class="title">风控指令:</h3>
                    <el-form label-width="110px" size="small">
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="外部指令序号:"
                                    ><el-input :value="instruction.outerOrderCode" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>

                        <el-row class="form-row">
                            <el-col :span="12">
                                <!-- <el-form-item label="下单模式:">
                  <el-select v-model="instruction.directMode" size="mini">
                    <el-option v-for="i in directModeSelectData" :key="i.dictKey" :label="i.dictKey + ' ' + i.dictKeyName" :value="i.dictKey">
                    </el-option>
                  </el-select>
                </el-form-item> -->
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="指令类型:">
                                    <el-select v-model="instruction.instructionType" size="mini" @change="handleTypeChange">
                                        <el-option
                                            v-for="i in instructionTypeSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-divider></el-divider>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="产品序号:">
                                    <RiskEntryInput @set-entry-data="getEntryslist" :returnDatas="instruction.fundCode" />
                                    <!-- <el-select v-model="instruction.fundCode" filterable @change="handleFundCodeChange" size="mini">
                                        <el-option
                                            v-for="i in fundCodeSelectData"
                                            :key="i.fundCode"
                                            :label="i.fundCode + ' ' + i.fundNameSt"
                                            :value="i.fundCode"
                                        >
                                        </el-option>
                                    </el-select> -->
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="组合编码:">
                                    <el-select v-model="instruction.fundAccountCode" size="mini">
                                        <el-option
                                            v-for="i in computedFundAccountCodeSelectData"
                                            :key="i.fundAccountCode"
                                            :label="i.fundAccountCode + ' ' + i.fundAccountName"
                                            :value="i.fundAccountCode"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <BondTradingOrder v-if="instruction.instructionType === '1'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <RepurchaseOrder v-else-if="instruction.instructionType === '2'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <DepositOrder v-else-if="instruction.instructionType === '3'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <ExchangeOrder
                            v-else-if="instruction.instructionType === '4'"
                            @getRiskForm="getRiskForm"
                            @getStockName="getStockName"
                            :show="showStock"
                        />
                        <OneBondOrder v-else-if="instruction.instructionType === '5'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <FuturesOrder v-else-if="instruction.instructionType === '6'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <ExchangeBulkOrder v-else-if="instruction.instructionType === '7'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <CwOpenFundOrder v-else-if="instruction.instructionType === '8'" @getRiskForm="getRiskForm" @getStockName="getStockName" />
                        <UnderNetOrder v-else-if="instruction.instructionType === '9'" @getRiskForm="getRiskForm" @getStockName="getStockName" />

                        <el-divider></el-divider>
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="备注:"><el-input v-model="instruction.remark" size="mini"></el-input></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row" style="float: right">
                            <el-select style="width: 150px; margin-right: 10px" clearable v-model="instruction.directMode" size="mini">
                                <el-option label="有序从严控制" value="0">有序从严控制</el-option>
                                <el-option label="有序非从严控制" value="1">有序非从严控制</el-option>
                                <el-option label="无序从严控制" value="2">无序从严控制</el-option>
                                <el-option label="无序非从严控制" value="3">无序非从严控制</el-option>
                            </el-select>
                            <el-button v-authCode="B_0039" @click="handleRemake" size="mini">重置</el-button>
                            <el-button v-authCode="B_0041" @click="handleSubmit('1')" type="primary" size="mini">试算</el-button>
                            <el-button v-authCode="B_0040" @click="handleSubmit('2')" type="primary" size="mini">下单</el-button>
                        </el-row>
                    </el-form>
                </el-col>
                <el-col :span="16" class="col-box security-box">
                    <div v-if="instruction.instructionType !== '3'">
                        <el-button type="primary" size="mini" @click="handleAddStock">添加证券</el-button>
                        <div style="margin-top: 10px">
                            <vxe-table :data="selectedStockList" border size="mini" style="width: 100%" header-align="center">
                                <vxe-column title="操作">
                                    <template slot-scope="scope">
                                        <el-button icon="el-icon-close" size="mini" @click="handleDelSelect(scope.row)" type="primary"></el-button>
                                    </template>
                                </vxe-column>
                                <vxe-column field="stockCode" title="证券代码" show-overflow></vxe-column>
                                <vxe-column field="stockNameSt" title="证券名称" show-overflow></vxe-column>
                                <vxe-column field="reportCode" title="申报代码" show-overflow></vxe-column>
                                <vxe-column field="stockType" title="证券类别" show-overflow>
                                    <template slot-scope="scope">
                                        <span>{{ StockTypePojo[scope.row.stockType] }}</span>
                                    </template>
                                </vxe-column>
                                <vxe-column field="marketCode" title="市场类型">
                                    <template slot-scope="scope">
                                        <span>{{ MarketTypePojo[scope.row.marketCode] }}</span>
                                    </template>
                                </vxe-column>
                            </vxe-table>
                        </div>
                    </div>

                    <div v-else>
                        <el-button type="primary" size="mini" @click="bankCodeDialog = true">添加银行</el-button>
                        <div style="margin-top: 10px">
                            <vxe-table :data="selectedBankList" border size="mini" style="width: fit-content" header-align="center">
                                <vxe-column field="bankCode" title="银行代码" show-overflow></vxe-column>
                                <vxe-column field="bankName" title="银行名称" show-overflow></vxe-column>
                                <vxe-column field="bankNameSt" title="银行简称" show-overflow></vxe-column>
                            </vxe-table>
                        </div>
                    </div>
                </el-col>
            </el-row>
            <search-stock
                :stockCodeDialog="stockCodeDialog"
                :queryStockForm="queryStockForm"
                :disabled="disabled"
                @closeDialog="closeDialog"
                @getStock="getStock"
            ></search-stock>

            <search-bank
                :bankCodeDialog="bankCodeDialog"
                :queryBankForm="queryBankForm"
                @closeBankDialog="closeBankDialog"
                @getBank="getBank"
            ></search-bank>
        </div>
        <el-row class="row-height bottom-row">
            <el-col class="col-box">
                <h3 class="title">
                    <el-row>
                        <el-col :span="3">风控结果:<status-tag :code="riskResult"></status-tag></el-col>
                        <el-col :span="6">
                            <span>试算/下单时间: </span>
                            <span style="color: red">{{ calcTime }}</span>
                        </el-col>
                        <el-col :span="5">
                            <span>计算耗时: </span>
                            <span style="color: red">{{ takeTime }}</span>
                        </el-col>
                        <el-col :span="4"
                            >条目检查数:
                            <span v-show="riskResListMsg.returnData.data.length" style="color: red">{{
                                riskResListMsg.returnData.data.length
                            }}</span></el-col
                        >
                    </el-row>
                    <el-divider></el-divider>
                </h3>
                <!-- 风控结果表 -->
                <RiskResult :riskResultTable="riskResultTable" :stockInfoPojo="stockInfoPojo" />
            </el-col>
        </el-row>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import RiskTable from '@/common/components/risk-table.vue';
import DictionConstUtil, { SGU_CACHE, objToArr } from '@/utils/diction-const-util';
import Invest from '@/common/dict/invest';
import { UUID, NumberToWords } from '@/utils/tools';
import StatusTag from '../status-tag.vue';
import BranchTag from '../branch-tag.vue';
import RiskResult from '../risk-result.vue';

import { getUser } from '@/utils/user-util';
import BondTradingOrder from '../batch-invest/order-form/bond-trading-order.vue';
import RepurchaseOrder from '../batch-invest/order-form/repurchase-order.vue';
import DepositOrder from '../batch-invest/order-form/deposit-order.vue';
import ExchangeOrder from '../batch-invest/order-form/exchange-order.vue';
import OneBondOrder from '../batch-invest/order-form/one-bond-order.vue';
import FuturesOrder from '../batch-invest/order-form/futures-order.vue';
import ExchangeBulkOrder from '../batch-invest/order-form/exchange-bulk-order.vue';
import CwOpenFundOrder from '../batch-invest/order-form/cw-open-fund-order.vue';
import UnderNetOrder from '../batch-invest/order-form/under-net-order.vue';
import SearchStock from '../search-stock.vue';
import SearchBank from '../search-bank.vue';
import RiskEntryInput from '@/common/components/risk-entry-input.vue';

@Component({
    name: 'ExchangeBatchStock',
    components: {
        RiskTable,
        StatusTag,
        BranchTag,
        BondTradingOrder,
        RepurchaseOrder,
        DepositOrder,
        ExchangeOrder,
        OneBondOrder,
        FuturesOrder,
        ExchangeBulkOrder,
        CwOpenFundOrder,
        UnderNetOrder,
        SearchStock,
        SearchBank,
        RiskResult,
        RiskEntryInput,
    },
})
export default class ExchangeBatchStock extends Vue {
    // 风控指令表单
    instruction = {
        instructionType: '1',
        // directMode: '1',
        outerOrderCode: '自动生成',
        remark: '',
        directMode: '0',
        fundCode: '',
        fundAccountCode: '',
    };

    stockInfoPojo: any = {};

    // 证券查询表单
    queryStockForm = {
        stockCode: '',
        stockNameSt: '',
        stockType: '',
        marketCode: '',
        multMarketCode: [],
        multStockType: [],
    };

    // 银行查询表单
    queryBankForm = {
        bankCode: '',
        bankName: '',
        bankType1: '',
        sourceType: '',
    };
    // 是否显示证券代码
    showStock: boolean = false;
    multStockType: string[] = [];
    multMarketCode: string[] = [];

    // 证券信息相关
    stockMessageMsg = { url: '/baseInfomation/stockCode/', returnData: {} };

    // 产品信息相关
    positionsListMsg = {
        returnData: { data: [], total: 0 },
        dataKey: 'data',
    };
    // 风控结果相关
    riskResListMsg = {
        url: '/dataEngine/order/multiOrder',
        returnData: { data: [] },
        dataKey: 'data',
        height: '350px',
        // 隐藏页码
        hidePage: true,
        checked: { on: false, option: false },
    };

    // 风控结果表数据
    riskResultTable: any[] = [];

    // 显示证券代码选择弹框
    stockCodeDialog: boolean = false;

    // 银行信息弹框
    bankCodeDialog: boolean = false;

    // 图标dom
    iconDom: any = null;

    tableKey: any;

    Invest: any = new Invest();
    DictionConstUtil: any = new DictionConstUtil();

    // 下单模式下拉数据
    directModeSelectData: any[] = [];

    // 指令类型下拉数据
    instructionTypeSelectData: any[] = [];

    // 已添加的产品
    selectFundDataSource: any[] = [];
    StockTypePojo: any = {};
    MarketTypePojo: any = {};

    // 产品序号
    fundCode: string = '';

    // 组合编码
    fundAccountCode: string[] = [];
    fundCodeSelectData: any[] = []; // 产品序号下拉框数据
    fundAccountCodeSelectData: any[] = []; // 组合编码下拉框数据

    renderUUID: any;

    flag: boolean = false;

    // 子组件表单
    instructionForm: any = {};

    stockInfo = {
        stockCode: '',
        stockNameSt: '',
        reportCode: '',
        stockType: '',
        marketCode: '',
    };

    disabled: boolean = false;

    // 选中的证券
    selectedStockList: any[] = [];
    stockTypeList: string[] = [];

    // 选中的银行
    selectedBankList: any[] = [];

    calcTime: string = ''; // 下单/试算时间

    takeTime: string | number = ''; // 计算耗时

    riskResult: string | number = ''; // 风控结果

    entryType = {}; // 风险类型字典

    compareDirection = {}; // 比较方向字典

    selectedList: any[] = []; // 已选择的证券

    async mounted() {
        DictionConstUtil.FNMarketType().then(result => {
            this.$set(this, 'MarketTypePojo', DictionConstUtil.ListToPojo(result));
        });
        DictionConstUtil.FNStockType().then(result => {
            this.$set(this, 'StockTypePojo', DictionConstUtil.ListToPojo(result));
        });
        // 获取下单模式下拉数据
        // this.directModeSelectData = objToArr(DictionConstUtil.DirectMode);
        // 获取指令类型下拉数据
        this.instructionTypeSelectData = objToArr(this.Invest.instructionType);
        // 获取产品信息 (产品序号下拉框数据)
        this.fundCodeSelectData = await SGU_CACHE('FundInfo', '/fundInfo/list', []);
        // 获取组合编码下拉框数据
        let arr = await SGU_CACHE('FundAccount', '/fundInfo/accounts', []);
        arr.forEach(item => {
            this.fundAccountCodeSelectData[item.fundCode] = item.fundAccounts;
        });
        this.renderUUID = UUID();

        // 获取风险类型字典
        this.entryType = this.Invest.entryType;
        // 获取比较方向字典
        this.compareDirection = this.Invest.CompareDirection;
        // 重新渲染表格
        // this.changeData();
    }

    // 组合编码下拉框计算属性
    get computedFundAccountCodeSelectData() {
        return this.fundAccountCodeSelectData[this.instruction.fundCode] || [];
    }

    // 监听 组合编码计算属性 (每当计算属性变动时 自动选中第一项)
    @Watch('computedFundAccountCodeSelectData', { immediate: true, deep: true })
    watchcomputedFundAccountCode(newData) {
        if (newData && newData.length) {
            this.instruction.fundAccountCode = newData[0].fundAccountCode;
        }
    }

    // 删除选中证券事件
    handleDelSelect(row: any) {
        this.selectedStockList = this.selectedStockList.filter(item => item.positionId !== row.positionId);
    }

    // 根据指令类型添加限制条件
    async getMS() {
        this.multStockType = [];
        this.multMarketCode = [];
        if (this.instruction.instructionType === '1') {
            if (!this.instructionForm.orderDirection || this.instructionForm.orderDirection == '') {
                this.multStockType = ['15', '3', '4', '5', '6', '>', 'D', 'G', 'K', 'S', 'T'];
            } else {
                let stockTypeList: any = await this.getStockTypeByDirection(this.instructionForm.orderDirection);
                this.multStockType = stockTypeList;
            }
        } else if (this.instruction.instructionType === '2') {
            this.multStockType = ['-', '8', 'I'];
            this.multMarketCode = ['1', '2', '5'];
        } else if (this.instruction.instructionType === '4') {
            this.multMarketCode = ['H', '1', '2', '6', 'n', 'o', 'j'];
        } else if (this.instruction.instructionType === '6') {
            this.multStockType = ['R', 'W', 'v'];
            this.multMarketCode = ['3', '4', '7', '9'];
        } else if (this.instruction.instructionType === '7') {
            this.multMarketCode = ['1', '2'];
        } else if (this.instruction.instructionType === '8') {
            this.multStockType = ['F'];
            this.multMarketCode = ['6'];
        } else if (this.instruction.instructionType === '9') {
            this.multStockType = ['a', '1', 'C', '5'];
            this.multMarketCode = ['1', '2'];
        } else {
            this.multStockType = [];
            this.multMarketCode = [];
        }
        this.queryStockForm.multMarketCode = this.multMarketCode;
        this.queryStockForm.multStockType = this.multStockType;
    }

    // 添加证券按钮点击事件
    handleAddStock() {
        this.getMS();
        this.stockCodeDialog = true;
    }

    getStockTypeByDirection(orderDirection) {
        return new Promise((resolve, reject) => {
            this.$axios
                .get('dict/query/stockTypeByDirection/' + orderDirection)
                .then((res: any) => {
                    this.stockTypeList = res;
                    resolve(res);
                })
                .catch(err => {
                    reject(err);
                });
        });
    }

    getEntryslist(val: any) {
        this.instruction.fundCode = val;
        this.handleFundCodeChange();
    }

    handleFundCodeChange() {
        this.fundAccountCode = [];
    }

    getBank(val) {
        console.log(val);
        if (!this.selectedBankList.find(item => item.bankCode === val.bankCode)) {
            this.selectedBankList.unshift({
                key: val.bankCode + '-' + val.bankNameSt,
                bankCode: val.bankCode,
                bankNameSt: val.bankNameSt,
                bankName: val.bankName,
            });
        }
    }

    getStockName(val: any) {
        console.log(val, 'hhh');

        // this.stockInfoPojo = val;
    }

    getStock(val: any) {
        for (const key in this.stockInfo) {
            this.stockInfo[key] = val[key];
        }
        console.log(this.stockInfo, 'info');

        if (!this.selectedStockList.find(item => item.stockCode === val.stockCode)) {
            this.selectedStockList.unshift({
                key: this.stockInfo.stockCode + '-' + this.stockInfo.stockNameSt,
                stockCode: this.stockInfo.stockCode,
                stockNameSt: this.stockInfo.stockNameSt,
                reportCode: this.stockInfo.reportCode,
                stockType: this.stockInfo.stockType,
                marketCode: this.stockInfo.marketCode,
            });
            this.stockInfoPojo[this.stockInfo.stockCode] = this.stockInfo.stockNameSt;
        }
    }

    // 批量指令组装
    createBatchInstruction(collective, factInstruction, orderType) {
        let requestId = 'reb' + UUID() + '-' + new Date().getTime();
        let instructionPojo = {
            requestId: requestId,
            instructionType: collective.instructionType,
            orderType: orderType,
            // directMode: collective.directMode,
            multiType: '2',
            outOrderBatchCode: UUID() + '-' + new Date().getTime(),
            tradeUser: getUser().userCode,
            instList: [],
            directMode: '',
        };
        if (orderType === '1') {
            // instructionPojo.strict = this.instruction.strict;
            instructionPojo.directMode = this.instruction.directMode;
        }
        // let selectedList: any[] = [];
        if (this.instruction.instructionType !== '3') {
            this.selectedList = JSON.parse(JSON.stringify(this.selectedStockList));
        } else {
            this.selectedList = JSON.parse(JSON.stringify(this.selectedBankList));
        }

        let instList = [];

        for (let i = 0; i < this.selectedList.length; i++) {
            console.log(this.selectedList[i].reportCode);
            instList.push(
                JSON.stringify({
                    ...factInstruction,
                    orderType: orderType,
                    requestId: requestId,
                    instructionType: collective.instructionType,
                    outerOrderCode: 'eb' + UUID() + String(i) + '-' + new Date().getTime(),
                    marketCode: collective.instructionType === '3' ? '6' : this.selectedList[i].marketCode,
                    reportCode: this.selectedList[i].reportCode,
                    bankCode: this.selectedList[i].bankCode,
                    remark: collective.remark,
                    fundCode: collective.fundCode,
                    fundAccountCode: collective.fundAccountCode,
                })
            );
        }
        instructionPojo.instList = JSON.parse(JSON.stringify(instList));
        return instructionPojo;
    }

    // 转表格筛选下拉框数据
    objToArr(param) {
        let list = [];
        for (let key in param) {
            list.push({ label: param[key], value: key });
        }
        return list;
    }

    closeDialog() {
        this.stockCodeDialog = false;
    }

    closeBankDialog() {
        this.bankCodeDialog = false;
    }

    handleTypeChange() {
        this.getMS();
        this.selectedStockList = [];
    }

    // 校验提交参数
    verifyInstructionPamessageram(instruction, instructionType) {
        if (instructionType !== '3') {
            if (!this.selectedStockList || this.selectedStockList.length === 0) {
                this.yh_message_error('至少添加一个证券或银行');
                return false;
            }
        } else {
            if (!this.selectedBankList || this.selectedBankList.length === 0) {
                this.yh_message_error('至少添加一个证券或银行');
                return false;
            }
        }

        if (instructionType === '1') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '2') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.firstSettleDate) {
                this.yh_message_error('首次交割日不可为空');
                return false;
            }
            if (!instruction.endSettleDate) {
                this.yh_message_error('到期交割日不可为空');
                return false;
            }
            if (!instruction.clearSpeed) {
                this.yh_message_error('清算速度不可为空');
                return false;
            }
            if (!instruction.settleType) {
                this.yh_message_error('结算方式不可为空');
                return false;
            }
            if (!instruction.repoDay) {
                this.yh_message_error('回购天数不可为空');
                return false;
            }
            if (instruction.interest !== 0 && !instruction.interest) {
                this.yh_message_error('利息金额不可为空');
                return false;
            }
        } else if (instructionType === '3') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.depositStartDate) {
                this.yh_message_error('起息日不可为空');
                return false;
            }
            if (instruction.depositType === '2' && instruction.noticeType === '1' && !instruction.noticeDays) {
                this.yh_message_error('通知天数不可为空');
                return false;
            }

            if (!instruction.mutureDate && instruction.noticeType !== '1') {
                this.yh_message_error('到期日不可为空');
                return false;
            }
            if (!instruction.depositLimitTime) {
                this.yh_message_error('存款期限不可为空');
                return false;
            }
            if (!instruction.depositRate) {
                this.yh_message_error('存款利率不可为空');
                return false;
            }
            if (!instruction.depositType) {
                this.yh_message_error('存款类型不可为空');
                return false;
            }
        } else if (instructionType === '4') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '5') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderPrice) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (!instruction.orderAmount) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.fee) {
                this.yh_message_error('手续费不能为空');
                return false;
            }
            if (!instruction.firstSettleDate) {
                this.yh_message_error('首次交割日不能为空');
                return false;
            }
            if (!instruction.endSettleDate) {
                this.yh_message_error('到期交割日不能为空');
                return false;
            }
        } else if (instructionType === '6') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderPrice) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (!instruction.orderAmount) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '7') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderPrice) {
                this.yh_message_error('指令价格不可为空');
                return false;
            }
            if (!instruction.orderAmount) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
        } else if (instructionType === '8') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }
            if (!instruction.orderAmount) {
                this.yh_message_error('指令数量不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            if (!instruction.bulkType) {
                this.yh_message_error('巨额赎回标志不可为空');
                return false;
            }
        } else if (instructionType === '9') {
            if (!this.instruction.fundCode) {
                this.yh_message_error('产品代码不可为空');
                return false;
            }
            if (!this.instruction.fundAccountCode) {
                this.yh_message_error('组合编码不可为空');
                return false;
            }
            if (!instruction.orderDirection) {
                this.yh_message_error('订单方向不可为空');
                return false;
            }
            if (!instruction.orderUser) {
                this.yh_message_error('下单人不可为空');
                return false;
            }
            if (!instruction.investType) {
                this.yh_message_error('投资类型不可为空');
                return false;
            }

            if (!instruction.orderLevel) {
                this.yh_message_error('指令优先级不可为空');
                return false;
            }
            // if (!instruction.applyAmount) {
            //   this.yh_message_error('网下申购金额不可为空');
            //   return false;
            // }
            if (!instruction.winningRate) {
                this.yh_message_error('预估中签率不可为空');
                return false;
            }
        }
        return true;
    }

    // 获取指令表单
    getRiskForm(val) {
        this.instructionForm = val;
    }

    // 重置按钮事件
    handleRemake() {
        this.instruction = {
            instructionType: '1',
            // directMode: '1',
            outerOrderCode: '自动生成',
            remark: '',
            directMode: '0',
            fundCode: '',
            fundAccountCode: '',
        };
        this.selectedStockList = [];
        this.renderUUID = UUID();
    }

    // 提交事件
    handleSubmit(orderType: string) {
        this.flag = true;
        // 校验参数规则
        if (!this.verifyInstructionPamessageram(this.instructionForm, this.instruction.instructionType)) {
            return;
        }
        console.log(this.instructionForm);

        let instruction = this.createBatchInstruction(this.instruction, this.instructionForm, orderType);
        // 获取当前提交时间 (试算/下单时间)
        // 补零
        let fillZero = n => {
            let result = n.toString().length === 1 ? '0' + n : n;
            return result;
        };
        // 时间戳转换 yyyy-MM-dd
        let formatTime = (t = new Date()) => {
            let d = new Date(t);
            let year = d.getFullYear();
            let month = d.getMonth() + 1;
            let date = d.getDate();
            let hours = d.getHours();
            let minutes = d.getMinutes();
            let seconds = d.getSeconds();
            let result = `${year}-${fillZero(month)}-${fillZero(date)} ${fillZero(hours)}:${fillZero(minutes)}:${fillZero(seconds)}`;
            return result;
        };
        // 计算耗时
        let start = window.performance.now();
        this.calcTime = formatTime(new Date());
        // 提交指令 => 获取风控结果
        this.$axios.post(this.riskResListMsg.url, instruction).then((res: any) => {
            this.yh_message_success('指令信息提交成功');
            // 风控结果
            this.riskResult = res.thresholdType;
            // 计算耗时
            let end = window.performance.now();
            this.takeTime = ((end - start) / 1000).toFixed(3) + '秒';

            let data = res.resultList || [];

            // 根据产品代码 匹配产品名称
            data.forEach(ele => {
                ele.requestId = res.requestId;
                // 风险类型
                ele.entryType2 = this.entryType[ele.entryType];
                // 比较方向
                ele.compareType2 = this.compareDirection[ele.compareType];

                for (let i = 0; i < this.fundCodeSelectData.length; i++) {
                    const item = this.fundCodeSelectData[i];
                    if (ele.fundCode === item.fundCode) {
                        ele.fundNameSt = item.fundNameSt;
                    }
                }
                ele.stockNameSt = this.stockInfoPojo[ele.stockCode];
            });
            this.$set(this.riskResListMsg.returnData, 'data', data);
            this.riskResultTable = this.riskResListMsg.returnData.data;
        });
    }
}
</script>

<style lang="scss" scoped>
@import '@/pages/risk-measure/style/measure';

#exchange-batch-stock {
    width: 100%;
    height: 100vh;
    min-height: 600px;
    min-width: 1200px;
    .title {
        color: #575757;
        margin-right: 10px;
    }
    .el-divider--horizontal {
        height: 0.5px;
    }
    /deep/ .el-dialog__body {
        max-height: 70vh;
    }
    .row-height {
        .col-box {
            // height: 100%;
            padding: 10px 5px;
            .el-divider {
                margin: 0;
                margin-top: 5px;
            }
            .form-row {
                margin-top: 3px;
                .el-form-item--small {
                    margin: 0;
                    & /deep/ .el-form-item__label {
                        color: #575757;
                    }
                    & /deep/ .el-input__inner {
                        height: 28px;
                        line-height: 28px;
                    }
                }
            }
        }
        .security-box {
            .form-row {
                .el-form-item--small {
                    & /deep/ .el-input__inner {
                        background: #fff;
                        color: #575757;
                    }
                }
                .el-input {
                    display: inline-table;
                    /deep/ .el-input-group__append {
                        padding: 0 10px !important;
                    }
                }
            }
        }
        .left-p {
            position: absolute;
            right: 0px;
            top: 3px;
            height: 28px;
            display: flex;
            align-items: center;
            .el-icon-search {
                color: #fff;
            }
        }
        /deep/ .vxe-table--empty-placeholder {
            top: 20px !important;
            height: 150px !important;
        }
        // /deep/.vxe-table {
        //   height: 150px;
        //   max-height: 350px;
        // }
    }
}
</style>
